package com.barry.pattern.until;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class MyFileReader {


	private String[][] dirctory;

	/**
	 * @param URL
	 *         比如  : String URL = "F:\\\\chinese.txt";
	 */
	public String[][] readDictionary(String URL) {
		File file = new File(URL);
		try {
			FileReader reader = new FileReader(file);
			String temp;
			BufferedReader bufferedReader = new BufferedReader(reader);
		
			//获取字典长度
			bufferedReader.mark(8192);
			int lineNum=0;
			while ((temp = bufferedReader.readLine()) != null) {
				lineNum++;
			}	
			dirctory = new String[lineNum][2];

			//重新读取，把字典写到数组
			String[] strings;
			int len=0;
			bufferedReader.reset();
			while ((temp = bufferedReader.readLine()) != null) {
				strings = temp.toString().split("=");
				//System.err.println(temp.toString());
				if (strings.length==2) {
					dirctory[len][0]=strings[0];
					dirctory[len][1]=strings[1];
					
				}
				len++;
			}
			bufferedReader.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return dirctory;
	}
}
